package com.haoliangtian.api;


import android.util.Printer;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.CallAdapter;
import retrofit2.Converter;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * <br>
 * 2020/5/2010:03 PM
 *
 * @author 华软科技
 * @version 1.0
 */

public class APIUtil {
    private static APIService service;
    private static String baseUrl = "http://139.9.137.186:8888";
    private static Converter.Factory gsonConverterFactory = GsonConverterFactory.create();
    private static CallAdapter.Factory rxJavaCallAdapterFactory = RxJava2CallAdapterFactory.create();

    public static APIService getAPIService() {
        if (service == null) {
            OkHttpClient okHttpClient = new OkHttpClient.Builder()
                    .addInterceptor(new ProgressInterceptor())
                    .connectTimeout(20, TimeUnit.SECONDS)
                    .build();
            Retrofit build = new Retrofit.Builder()
                    .client(okHttpClient)
                    .baseUrl(baseUrl)
                    .addConverterFactory(gsonConverterFactory)
                    .addCallAdapterFactory(rxJavaCallAdapterFactory)
                    .build();
            service = build.create(APIService.class);
        }
        return service;
    }
}
